import React, { Component } from 'react'
import Child from './Child'

export default class App extends Component {
  state = {
    myUsername: '',
  }
  render() {
    return (
      <div>
        App
        <div>
          <h1>登录页</h1>
          <input
            type='text'
            value={this.state.myUsername}
            onChange={(e) => this.setState({ myUsername: e.target.value })}
          />

          <button onClick={() => console.log(this.state.myUsername)}>
            登录
          </button>
          <button
            onClick={() => {
              this.setState({
                myUsername: '',
              })
            }}
          >
            重置
          </button>
        </div>
        <div>
          <h1>child</h1>
          <Child myText='首页' />
          <Child myText={this.state.myUsername} />
        </div>
      </div>
    )
  }
}

/**
 * 受控组件
 */
